﻿#region Usings

using System;

#endregion

namespace Rail.Net.Common.Extensions
{
    public static class StringExtensions
    {
        public static DateTime CreateDateTime(this string input, DateTime date)
        {
            try
            {
                var days = Int32.Parse(input.Substring(0, 2));
                var hours = Int32.Parse(input.Substring(3, 2));
                var minutes = Int32.Parse(input.Substring(6, 2));
                var seconds = Int32.Parse(input.Substring(9, 2));

                return date.AddDays(days).AddHours(hours).AddMinutes(minutes).AddSeconds(seconds);
            }
            catch (Exception)
            {
                return date;
            }
        }

        public static TimeSpan CreateTimeSpan(this string input)
        {
            try
            {
                var days = Int32.Parse(input.Substring(0, 2));
                var hours = Int32.Parse(input.Substring(3, 2));
                var minutes = Int32.Parse(input.Substring(6, 2));
                var seconds = Int32.Parse(input.Substring(9, 2));

                return new TimeSpan(days, hours, minutes, seconds);
            }
            catch (Exception)
            {
                return new TimeSpan();
            }
        }
    }
}